package tmproject.hlhj.fhp.tmvote.module

import android.content.Context
import com.example.mymvp.BaseModule
import com.lzy.okgo.model.Response
import tmproject.hlhj.fhp.tmvote.beans.AppColorBean
import tmproject.hlhj.fhp.tmvote.beans.VoteListBean
import tmproject.hlhj.fhp.tmvote.log
import tmproject.hlhj.fhp.tmvote.network.Apis
import tmproject.hlhj.fhp.tmvote.network.BaseObersever

/**
 * Created by Never Fear   on 2018\8\6 0006.
Never More....
 */
class VoteListModule :BaseModule{
    var listener:VoteListResp?=null
    /*获取列表数据*/
    fun getVoteListData(page:Int,pageSize:Int,context:Context){
        Apis.getActiveList(page,pageSize)?.let {
            it.subscribe(object :BaseObersever<Response<VoteListBean>>(context){
                override fun onRespSuccess(t: Response<VoteListBean>) {
                    val body = t.body()
                    listener?.onResp(body)
                }

                override fun onError(e: Throwable?) {
                    super.onError(e)

                }

                override fun onRespErro(t: Response<VoteListBean>) {
                    log("okgo","错误")
                    super.onRespErro(t)

                }
            })
        }
    }
    /*获取主题颜色*/
    fun getAppColor(context: Context){
        Apis.getAPPColor()?.let {
            it.subscribe(object :BaseObersever<Response<AppColorBean>>(context){
                override fun onRespSuccess(t: Response<AppColorBean>) {
                    val appColorBean = t.body()
                    log("okgo","都没到这来？？？")
                    listener?.onColorBack(appColorBean)
                }

                override fun onacheSuccess(t: Response<AppColorBean>) {
                    super.onacheSuccess(t)
                    listener?.onColorBack(t.body())
                }
            })
        }
    }
    interface VoteListResp {
        fun onResp(voteListBean: VoteListBean)
        fun onColorBack(appColorBean: AppColorBean)
    }
}